from __future__ import division
from camfr import *

c = 2.99792458e14

lam0 = 1.55
set_lambda(lam0)
set_polarisation(TE)
set_N(1)
k0 = 2*pi/lam0
f0 = c/lam0 * 1e-9 # GHz

n_w = 1.469031751
t_core = 0.099
t_clad = 15.0
u_clad = 0.6
w_core_a = 5.0
w_core_io = 5.0
da = 0.4+w_core_a
Nch = 8
df = 400.0 # GHz
Xtalk_factor = 1.8

Air = Material(1.0)
SiO2 = Material(1.45)
Si3N4 = Material(1.98)

n_tl = SiO2.n().real

core = Slab( SiO2(t_clad) + Si3N4(t_core) + SiO2(u_clad) + Air(3.0) )
core.calc()
n_tc = core.mode(0).n_eff().real

V = k0*w_core_io*sqrt(n_tc**2.0-n_tl**2.0)
print 'V = ', V

dr = w_core_io*Xtalk_factor
print 'dr = ', dr, ' um'

Theta0 = lam0 / ( n_tc*w_core_io*(0.5 + 1/(V-0.6))*sqrt(2*pi) )
print 'Theta0 = ', Theta0, ' radians'

Theta_max = sqrt(3*Theta0**2.0/(20*log10(exp(1.0))))
print 'Theta_max = ', Theta_max, ' radians'

Ra = (Nch -1) * dr/(2*Theta_max)
print 'Ra = ', Ra, ' um'

DL = dr*f0*n_w*da / (df*n_tc*Ra)
print 'DL = ', DL, ' um'

Na = 2*3*Theta0*Ra/da + 1
print 'Na = ', Na
